package org.afeng;

import java.util.Random;
import java.util.Scanner;

/**
 * @description:
 * @author: liqf
 * @create: 2022-06-05 15:00
 **/
public class Game {

    public final static char[] chars = new char[]{
            'a', 'b', 'c', 'd', 'e', 'f', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'
    };

    static Scanner scanner = new Scanner(System.in);

    static int count = 0;

    @Deprecated
    public static void enterGame() {
        System.out.println("Home.enterGame");
        char aChar = chars[new Random().nextInt(chars.length)];
        System.out.println(aChar);

        while (scanner.hasNextLine()) {
            if (aChar == scanner.nextLine().toCharArray()[0]) {
                aChar = chars[new Random().nextInt(chars.length)];
                System.out.println(aChar);
                count++;
                continue;
            }
            break;
        }
        System.out.println("得分: " + count);
    }

    public static int enterGame2() {
//        System.out.println("Game.enterGame2");
//        System.out.println(" count = " + count);
        int oneCount = 0;
        char aChar = chars[new Random().nextInt(chars.length)];
        System.out.println("快速输入后面符号: "+aChar);

        if (scanner.hasNextLine()) {
            if (aChar == scanner.nextLine().toCharArray()[0]) {
//                aChar = chars[new Random().nextInt(chars.length)];
//                System.out.println(aChar);
                oneCount++;
            }else {
                return -1;
            }
        }
//        return count; //count线程安全
        return oneCount;
    }
}

